#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 3e4+10;
const int M = 1e4+10;

struct edge{int v;db w;int nxt;}e[M];
int h[N],cnt,n,m;
db dis[N],mid;
bool goal,vis[N];
void link(int x,int y,db w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void dfs(int x){
	if(goal) return; vis[x] = 1; for(int i = h[x],y;i && !goal;i = e[i].nxt) if(dis[y = e[i].v] > dis[x] + e[i].w - mid) {dis[y] = dis[x] + e[i].w - mid; if(vis[y]) return goal = 1,void(); dfs(y);} vis[x] = 0;
}

void reset(){for(int i = 1;i <= n;i++) dis[i] = vis[i] = 0;}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in; db l = 1e7,r = -1e7,w;
	for(int i = 1,u,v;i <= m;i++) u = in,v = in,scanf("%lf",&w),link(u,v,w),l = min(l,w),r = max(r,w);
	for(int i = 1;i <= 80;i++){
		goal = 0; mid = (l + r) / 2; reset();
		for(int x = 1;x <= n;x++) if(!goal) dfs(x);
		if(!goal) l = mid; else r = mid;
	}printf("%.8lf\n",mid);
	return 0;
}
